package com.example.mytransitiondemo.Transition;


import android.os.Bundle;
import android.transition.Explode;
import android.transition.Fade;
import android.transition.Slide;
import android.transition.TransitionInflater;
import android.view.Gravity;
import android.widget.TextView;

import com.example.mytransitiondemo.BaseActivity;
import com.example.mytransitiondemo.R;


public class TransitionToThisActivity extends BaseActivity {

    private String transition;
    private TextView textView;
    private boolean isXml;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transition_to_this);

        transition = getIntent().getStringExtra("transition");
        isXml = getIntent().getBooleanExtra("isXml", false);
        initAnimation();
    }

    private void initAnimation() {
        textView = (TextView) findViewById(R.id.share_text);
        textView.setText(transition);

        switch (transition) {
            case "explode":

                if (isXml) {
                    Explode explode = (Explode) TransitionInflater.from(this).inflateTransition(R.transition.explode);
                    explode.setDuration(1000L);
                    getWindow().setEnterTransition(explode);
                    return;
                }

                Explode explode = new Explode();
                explode.setDuration(1000L);
                getWindow().setEnterTransition(explode);
                break;
            case "slide":

                if (isXml) {
                    Slide slide = (Slide) TransitionInflater.from(this).inflateTransition(R.transition.slide);
                    slide.setDuration(1000L);
                    getWindow().setEnterTransition(slide);
                    return;
                }

                Slide slide = new Slide(Gravity.BOTTOM);
                slide.setDuration(1000L);
                getWindow().setEnterTransition(slide);
                break;
            case "fade":

                if (isXml) {
                    Fade fade = (Fade) TransitionInflater.from(this).inflateTransition(R.transition.fade);
                    fade.setDuration(1000L);
                    getWindow().setEnterTransition(fade);
                    return;
                }

                Fade fade = new Fade();
                fade.setDuration(1000L);
                getWindow().setEnterTransition(fade);
                break;
            default:
                break;
        }
    }
}
